﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms;
using System.Xml.Serialization;
using System.IO;

namespace IHM
{
    public partial class FenetreDemarrer : Window
    {
        public static int nombreJoueurs;

        private FenetreInitialisation fenetreSuivante = new FenetreInitialisation();

        public FenetreDemarrer()
        {
            InitializeComponent();
        }

        private void ClickCommencer(object sender, RoutedEventArgs e)
        {
            fenetreSuivante.Show();
            Close();
        }

        private void ClickCharger(object sender, RoutedEventArgs e)
        {
            IHMPartie partie = new IHMPartie();

            OpenFileDialog boiteOuverture = new OpenFileDialog();
            boiteOuverture.Filter = "Fichier xml(*.xml)|*.xml";
            if (boiteOuverture.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                partie = Charger(boiteOuverture.FileName);

                FenetreJeu fenetrePartieChargee = new FenetreJeu(partie);
                fenetrePartieChargee.Show();
                Close();
            }

        }

        public IHMPartie Charger(string filename)
        {
            FileStream file = File.Open(filename, FileMode.Open);
            XmlSerializer serializer = new XmlSerializer(typeof(IHMPartie));
            IHMPartie unepartie = (IHMPartie)serializer.Deserialize(file);
            file.Close();

            return unepartie;
        }
    }
}
